package com.blogs.ui;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blogs.component.BaseActivity;
import com.blogs.component.CateAdapter;
import com.blogs.entity.CateFeed;
import com.blogs.entity.ListDate;
import com.blogs.tools.DBSharedPreferences;
import com.cnblogs.R;

public class SubCateSelect extends BaseActivity implements OnItemClickListener{
	private ArrayList<CateFeed> catelList;
	private ListView catel_list;
	private CateAdapter cateAdapter;
	private DBSharedPreferences sp;
	private Button title_include_back;
	private TextView title_include_title;
	private RelativeLayout title_top_bg;
	private int name_site_categroy_id;
	private LinearLayout sub_cate_select_body;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub_cate_select);
		sp= new DBSharedPreferences(this);
		ViewGroup headview=(ViewGroup)findViewById(R.id.main_title_include);
		title_include_title=(TextView)headview.findViewById(R.id.title_include_title);
		title_include_back=(Button)headview.findViewById(R.id.title_include_back);
		title_include_title.setText("频道选择");
		title_include_back.setVisibility(View.VISIBLE);
		title_include_back.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		sub_cate_select_body=(LinearLayout)findViewById(R.id.sub_cate_select_body);
		title_top_bg=(RelativeLayout)headview;
		this.initList();
		this.InitSkin();
	}
	private void InitSkin()
	{
		if(sp.GetIsDarkState())
		{
			title_top_bg.getBackground().setLevel(2);
			sub_cate_select_body.getBackground().setLevel(2);
		}
		else
		{
			title_top_bg.getBackground().setLevel(1);
			sub_cate_select_body.getBackground().setLevel(1);
		}
	}
	
	private void initList()
	{
		name_site_categroy_id=getIntent().getIntExtra("name_site_categroy_id", -1);
		name_site_categroy_id=name_site_categroy_id==-1?0:name_site_categroy_id;
		catelList=ListDate.getCatelList();
		
		catel_list=(ListView)findViewById(R.id.sub_cate_select_lv);
		catel_list.setDivider(getResources().getDrawable(R.drawable.line_01));
		catel_list.setCacheColorHint(Color.TRANSPARENT);
		cateAdapter=new CateAdapter(this,name_site_categroy_id, catelList);
		catel_list.setAdapter(cateAdapter);
		catel_list.setOnItemClickListener(this);
		catel_list.setSelection(name_site_categroy_id);
	}
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		if(catelList.get(position).cate_id==0)
			return;
		Intent result = new Intent();
		result.putExtra("name_site_categroy_id", position);
		setResult(RESULT_OK,result);
		finish();
	}
}
